<?php
class DigFile_Model_Symlink extends DigFile_Model_Resource {
    public $type = 'dir';
    public $is_loaded = 'false';

    public static function getRootDir() {
        return new self(Dig_Service_Module::settings('digFile', 'rootPath'));
    }
    
    public function addDir($dirname) {
        return mkdir($this->rootPath() . '/' . $dirname);
    }

    public function valid() {
        return $this->isDir();
    }

    public function hasChildren() {
        // directories i.e. "." and ".." then the directory is not empty
        if ( ($files = @scandir($this->rootPath())) && (count($files) > 2) ) {
            return true;
        }
    }

    public function children() {
        $dirs = array();
        $files = array();
        $contents = scandir($this->rootPath());
        if(count($contents) > 0) {
            foreach ($contents as $child) {
                if($child != '.' && $child != '..') {
                    $model = DigFile_Model_Resource::factory($this->filepath() . '/' . $child);
                    if($model->isDir()) {
                        $dirs[] = $model;
                    } else {
                        $files[] = $model;
                    }
                }
            }
        }
        $children = array_merge($dirs, $files);
        if(count($children) > 0) {
            return $children;
        }
    }
}
?>